//Line.hpp
#ifndef _LINE_HPP_
#define _LINE_HPP_
#include <iostream>
#include <cmath>
#include "Point.hpp"
using namespace std;
class Line {
    private:
        Point *point1;
        Point *point2;

    public:
        Line() {//无参构造
            this->point1 = new Point();
            this->point2 = new Point();
        }    

        Line(Point point1, Point point2) {//通过两个Ponit对象初始化
            this->point1 = new Point(point1.getX(), point1.getY());
            this->point2 = new Point(point2.getX(), point2.getY());
        }

        Line(double x1, double y1, double x2, double y2) {//通过两个点的坐标初始化
            this->point1 = new Point(x1, y1);
            this->point2 = new Point(x2, y2);
        }

        Line(const Line& line) {//拷贝构造
            this->point1 = new Point(line.point1->getX(), line.point1->getY());
            this->point2 = new Point(line.point2->getX(), line.point2->getY());
        }

        ~Line() {//析构
            if (point1 != NULL) {
                delete point1;
            }

            if (point2 != NULL) {
                delete point2;
            }
        }

        double length() {   //求当前Line对象的长度
            return sqrt(pow(this->getPoint1()->getX() - this->getPoint2()->getX(), 2)
                    + pow(this->getPoint1()->getY() - this->getPoint2()->getY(), 2));
        }

        void displayPoint1() {
            cout << "(" << this->getPoint1()->getX() 
                << ", " << this->getPoint1()->getY() << ")";
        }

        void displayPoint2() {
            cout << "(" << this->getPoint2()->getX() 
                << ", " << this->getPoint2()->getY() << ")";
        }

        //以下为getter和setter
        Point* getPoint1() {
            return point1;
        }

        void setPoint1(Point& point) {
            this->point1->setX(point.getX());
            this->point1->setY(point.getY());
        }

        Point* getPoint2() {
            return point2;
        }

        void setPoint2(Point& point) {
            this->point2->setX(point.getX());
            this->point2->setY(point.getY());
        }
};
#endif